//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "aisuppress\fn_getCover.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_unit","_fps"];
DEFAULT_PARAM(_unit,0,objNull);
_fps = diag_fps;
if (!isnull _unit && _fps >= GVAR(MIN_FPS)) then {
	[_unit] call FUNC(addSphere);
	
	_last_fired = _unit getVariable [QGVAR(LAST_FIRED),-10];
	_bullet_cnt = _unit getVariable [QGVAR(BULLET_COUNT),0];
	TRACE_1("Checks",ARR_2((time - _last_fired),_bullet_cnt));
	if ((time - _last_fired) > 10 || (_bullet_cnt >= GVAR(MIN_BULLET_FOR_FLEE))) then {
		if (random(100) > 20) then {
			[_unit] call FUNC(findCover);
		} else {
			[_unit] call FUNC(endSuppression);
		};
	} else {
		[_unit,[1,0,0]] call FUNC(setSphereColor);
	};
} else {
	if (!isNull _unit) then {
		TRACE_1("Cannot start suppression",ARR_2(_unit,_fps));
		[_unit] call FUNC(endSuppression);
	};
};

TRACE("End");
TMFPROFILERSTOP;
